<?php

Class Mdokter extends CI_Model{
	
	function __construct(){
		$this->load->database();
	}
	
	function create_dokterid(){
		
		//diambil dari database berdasarkan formatnya
		$idtype = "dokter_id";

		$year   = date('y');
		$sql    = "select id from idgen where type_id = '$idtype'";
		$row    = $this->db->query($sql)->row();
		$id     = $row->id;
		//$id     += 1;
		
		return sprintf('1%02d%04d',$year,$id);
	}
	
	function simpan($dokterid,$nama,$alamat,$kota,$tlp,$fax,$hp,$poli){
	
		$reg_date = date("Y-m-d H:i:s");
		$username = "ogi";
		
		$sql = "insert into dokter(dokter_id,nama,alamat,kota,tlp,fax,hp,reg_date,poli_id,username) 
			   values('$dokterid','$nama','$alamat','$kota','$tlp','$fax','$hp','$reg_date','$poli','$username')";
		$this->db->query($sql);
		
		$sql = "update idgen set id = id+1 where type_id = 'dokter_id'";
		return $this->db->query($sql);
	}
	
	function daftar_dokter(){
		$sql = "select * from dokter";
		return $this->db->query($sql)->result();
	}
}